#include "HighScoreState.h"
#include "stdafx.h"
#include "..\\SGD Wrappers\SGD_String.h"

/**************************************************************/
// GetInstance
//	- store the ONLY instance in global memory
//	- return the only instance by pointer
/*static*/ HighScoreState* HighScoreState::GetInstance(void)
{
	static HighScoreState s_Instance;

	return &s_Instance;
}


/**************************************************************/
// Enter
//	- reset the game & load resources
void HighScoreState::Enter(void)
{
	page = 0;

	// Set background color
	SGD::GraphicsManager::GetInstance()->SetClearColor({ 50, 50, 50 });	// dark gray
}

/**************************************************************/
// Exit
//	- deallocate / unload resources
/*virtual*/ void HighScoreState::Exit(void)
{

}

/**************************************************************/
// Input
//	- Handles User Input
bool HighScoreState::Input()
{
	SGD::InputManager* pInput = SGD::InputManager::GetInstance();

	if (Game::GetInstance()->MenuBackInput())
		Game::GetInstance()->ChangeState(MainMenuState::GetInstance());

	if (theGame->MenuRightInput())
	{
		++page;

		// Wrap around
		if (page > 3)		// should enumerate the options
			page = 0;
	}
	else if (theGame->MenuLeftInput())
	{
		--page;

		// Wrap around
		if (page < 0)
			page = 3;
	}

	return true;
}
/**************************************************************/
// Update
//	- update Objects / animations
void HighScoreState::Update(float elapsedTime)
{
}
/**************************************************************/
// Render
//	- Render Objects / animations
void HighScoreState::Render()
{
	// Use the game's font
	BitmapFont* pFont = Game::GetInstance()->GetFont();

	// Align text based on window width
	int width = (int)Game::GetInstance()->GetScreenWidth();

	//draw the background image
	SGD::GraphicsManager::GetInstance()->DrawTexture(theGame->GetMenuBackground(), { 0, 0 });

	// Display the game title centered at 4x scale
	pFont->Draw("HIGH SCORES", (int)((width - (11 * 32 * 1.0f)) / 2), 50, 1.0f, {});
	pFont->Draw(Game::GetInstance()->GetLevel(page).c_str(), (int)((width - (Game::GetInstance()->GetLevel(page).length() * 32 * 1.0f)) / 2), 100, 1.0f, {});

	std::ostringstream nameOutput;
	for (int i = 0; i < 10; i++)
	{
		nameOutput << Game::GetInstance()->GetName(page, i) << '\n';
	}

	std::ostringstream scoreOutput;
	for (int i = 0; i < 10; i++)
	{
		if (Game::GetInstance()->GetScore(page, i))
		{
			scoreOutput << Game::GetInstance()->GetScore(page, i) << '\n';
		}
		else
		{
			scoreOutput << "" << '\n';
		}
	}
	std::ostringstream comboOutput;
	for (int i = 0; i < 10; i++)
	{
		if (Game::GetInstance()->GetCombo(page, i))
		{
			comboOutput << Game::GetInstance()->GetCombo(page, i) << '\n';
		}
		else
		{
			comboOutput << "" << '\n';
		}
	}
	pFont->Draw(nameOutput.str().c_str(), 50, 200, 0.8f, { 255, 255, 255 });
	pFont->Draw(scoreOutput.str().c_str(), 620, 200, 0.8f, { 255, 255, 255 });
	pFont->Draw(comboOutput.str().c_str(), 350, 200, 0.8f, { 255, 255, 255 });

	//pFont->Draw("ESC (B) to return to Main Menu", 25, 500, .6, {});

}